package com.xigua.juc;

import java.util.HashSet;
import java.util.Set;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2021/8/2414:45
 */
public class VolatileTest {
     static volatile int x = 0,y = 0;
     static  volatile int a = 0,b = 0;
    public static void main(String[] args) throws InterruptedException {
        Set<String> set = new HashSet<>();
        for (int i = 0; i < 100000; i++) {
            x = 0;
            y = 0;
            a = 0;
            b = 0;
            Thread one = new Thread(()->{
                a = y;
                x = 1;
            });

            Thread other = new Thread(()->{
               b = x;
               y = 1;
            });

            one.start();
            other.start();
            one.join();
            other.join();

           set.add("a = "+a+",b = "+b);
            System.out.println(set);
        }

     }
}
